//全局的参数管理，一些不知道放哪的参数都可以丢这里
export default {
	namespaced: true,
	state: {
		clientType: "yxn-phone",
		// yxnAppid: "gsim-jiugelingcang-1658732423",
		yxnAppid: "gsim-test-1663234906",
		upLoadToken: null,
		baseImgUrl: '', //七牛云图片基础路径
		qiniuUrl: 'https://up-z2.qiniup.com', //七牛云上传路径
		base: {}
	},
	mutations: {

	},
	actions: {
		upload({
			state
		}, path) {
			return new Promise((resolve, reject) => {
				// uni.chooseImage({
				//  count: 1,
				//  sizeType: ['compressed'],
				//  sourceType: ['album', 'camera'],
				//  success: res => {
				//   let path = res.tempFilePaths[0];

				//  }
				// })
				uni.showLoading({
					title: '上传中'
				})
				uni.uploadFile({
					url: state.qiniuUrl,
					filePath: path,
					name: 'file',
					formData: {
						token: state.upLoadToken
					},
					success: res => {
						const data = JSON.parse(res.data)
						console.log(data)
						uni.showToast({
							title: '上传成功'
						})
						resolve(state.baseImgUrl + '/' + data.key)
					},
					fail: err => {
						console.log(err)
						uni.showToast({
							icon: 'none',
							title: '上传失败'
						})
						reject(err);
					}
				})
			})
		}
	}
}
